using System.Collections.Generic;
using UnityEngine;

public class SurvivalChanllenge : BaseTask
{
	public static SurvivalChanllenge instance;

	public int curwave;

	private List<int> wavelist;

	private List<int> waveAttlist;

	public override void MyUpdate()
	{
		if (timebegin)
		{
			stoptime += Time.deltaTime;
			if (Mathf.FloorToInt(stoptime) == 1)
			{
				timeone();
			}
			else if (Mathf.FloorToInt(stoptime) == 3)
			{
				timetwo();
			}
			else if (Mathf.FloorToInt(stoptime) == 4)
			{
				timethree();
			}
			else if (Mathf.FloorToInt(stoptime) == 5)
			{
				timefour();
			}
			if (stoptime >= 5f)
			{
				stoptime = 0f;
				timebegin = false;
			}
		}
		else if (!FinishState)
		{
			base.MyUpdate();
			if (plane_smothfollow.instance.isdied)
			{
				FinishState = true;
				isSuccess = false;
			}
		}
	}

	public override void MyStart()
	{
		base.MyStart();
		if (instance == null)
		{
			instance = this;
		}
		curwave = 1;
		TasksController.instance.curwave = -1;
		wavelist = new List<int>();
		waveAttlist = new List<int>();
		switch (GlobalInf.chanllenge_mode)
		{
			case 0:
				wavelist = DataController.instance.surdata[0].enemynum;
				waveAttlist = DataController.instance.surdata[0].enemyatt;
				break;
			case 1:
				wavelist = DataController.instance.surdata[1].enemynum;
				waveAttlist = DataController.instance.surdata[1].enemyatt;
				break;
			case 2:
				wavelist = DataController.instance.surdata[2].enemynum;
				waveAttlist = DataController.instance.surdata[2].enemyatt;
				break;
		}
		AIPool.instance.creat_plane_random(plane_smothfollow.instance.m_Transform, 5, 0);
		AIPool.instance.DisableAllAI();
	}

	public void CheckNum(int num)
	{
		if (num == 0 && !timebegin)
		{
			if (curwave == 20)
			{
				FinishState = true;
				isSuccess = true;
				TasksController.instance.curwave = 19;
				return;
			}
			timebegin = true;
			curwave++;
			TasksController.instance.curwave = curwave - 2;
			one = false;
			two = false;
			three = false;
			four = false;
		}
	}

	public override void MyEnd()
	{
		base.MyEnd();
		if (instance != null)
		{
			instance = null;
		}
	}

	public override void timeone()
	{
		base.timeone();
		if (!one)
		{
			one = true;
			UIController.instance.show_hitinfo("第 " + curwave + " 波将在 4 秒后开始");
			UIController.instance.hitinfo_appear();
		}
	}

	public override void timetwo()
	{
		base.timetwo();
		if (!two)
		{
			two = true;
			UIController.instance.show_hitinfo("第 " + curwave + " 波将在 3 秒后开始");
		}
	}

	public override void timethree()
	{
		base.timethree();
		if (!three)
		{
			three = true;
			UIController.instance.show_hitinfo("第 " + curwave + " 波将在 2 秒后开始");
		}
	}

	public override void timefour()
	{
		base.timefour();
		if (!four)
		{
			four = true;
			UIController.instance.show_hitinfo("第 " + curwave + " 波将在 1 秒后开始");
			UIController.instance.hitinfo_disappear();
			cread_wave_enemy();
		}
	}

	public void cread_wave_enemy()
	{
		AIPool.instance.creat_plane_random(plane_smothfollow.instance.m_Transform, wavelist[curwave - 1], waveAttlist[curwave - 1]);
	}
}
